﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UniversityStudentManagemnetSystem.BLL;

namespace UniversityStudentManagemnetSystem.UI
{
    public partial class TeacherInformationViewPage : System.Web.UI.Page
    {

        TeacherManager manager = new TeacherManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack!=true)
            {
                searchButton.Enabled = false;
                searchButton.Visible = false;

            }
            
        }

        private void PopulatedDepartmentDropDownList()
        {
            DepartmentManager departmentManager = new DepartmentManager();
            DataTable departments = departmentManager.GetAllDepartments();
            departmentDropDownList.DataTextField = "Name";
            departmentDropDownList.DataValueField = "Id";
            departmentDropDownList.DataSource = departments;
            departmentDropDownList.DataBind();
        }

        protected void departmentRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            
            PopulatedDepartmentDropDownList();
            allRadioButton.Checked = false;
            allRadioButton.Text = string.Empty;
            searchButton.Visible = true;
            searchButton.Enabled = true;

        }

        protected void allRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            searchButton.Visible = false;
            PopulatedAllButton();
        }

        private void PopulatedAllButton()
        {
            departmentRadioButton.Checked = false;
            departmentRadioButton.Text = string.Empty;
            GetAllTeacherInfomation();
            
        }

        protected void searchButton_Click(object sender, EventArgs e)
        {
            
            GetAllTeacherForTheirDepartment();
            //searchButton.Enabled = false;
           


        }

        private void GetAllTeacherForTheirDepartment()
        {
            int selectedDepartment = Convert.ToInt32(departmentDropDownList.SelectedValue);
            DataTable teacherTable = manager.GetAllTeachersFor(selectedDepartment);
            teacherInformationGridView.DataSource = teacherTable;
            teacherInformationGridView.DataBind();
        }

        private void GetAllTeacherInfomation()
        {
            DataTable teacherTable = manager.GetAllTeachers();
            teacherInformationGridView.DataSource = teacherTable;
            teacherInformationGridView.DataBind();
        }

        protected void teacherLinkButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("ViewSingleTeacherPersonalInformation.aspx");
        }
    }
}